package com.zyh.arraydemo;

public class ArrayDemo3 {
    /*
    将数组元素反转，原数组{5,12,90,18,77,76,45,28,59,72}
     */
//    方法一：
    public static void main1(String[] args) {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        for (int start = 0, end = arr.length - 1; start <= end; start++, end--) {
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "　");
        }
    }

    //    方法二：
    public static void main(String[] args) {
//        新建一个长度相等的新数组
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        int[] brr = new int[arr.length];
        for (int i = arr.length - 1; i >= 0; i--) {
            brr[i] = arr[arr.length - 1 - i];
        }
        for (int i : brr) {
            System.out.print(i + " ");
        }
    }

    //    方法三
    public static void main3(String[] args) {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        for (int i = 0; i < (arr.length - 1) / 2; i++) {
            arr[i] = arr[arr.length - 1 - i];
        }
        for (int i : arr) {
            System.out.print(i + "　");
        }
    }
}
